﻿package com.vfd.animation.tweens{

	import fl.transitions.Tween;

	import flash.utils.setTimeout;

	/**
	
	* @author Jeremy Wischusen <cortex@visualflowdesigns.com>
	
	* This class allows for a delay before starting the animation.
	
	*/

	public class DelayedTween extends Tween {

		/*
		
		Holds the number of seconds to wait before starting the animation. 
		
		*/

		private var _delay:Number = 0;

		public function DelayedTween(object, property, easingFunction, start, end, duration, useSeconds, delay = 0) {

			this.delay = delay ;

			super(object,property,easingFunction,start,end,duration,useSeconds);

		}

		/*Override the default start function so that the delay can be applied.*/

		public override function start():void {

			if (this._delay>0) {

				setTimeout(super.start,this._delay);

			} else {

				super.start();

			}

		}

		/*Setter function for delay attribute*/

		public function set delay(seconds:Number):void {
			trace("Setting delay to " + seconds);
			this._delay = Math.abs(seconds*1000);

		}

	}

}